#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <string.h>

void do_alarm(int sig) {
    printf("Receive signal <%s> \n", strsignal(sig));
}
// 设置定时器时长3s , 处理sigalarm信号
int main(int argc, char const *argv[])
{
    unsigned int ret;
    sig_t sigret;
    sigret = signal(SIGALRM, do_alarm);
    if (sigret == SIG_ERR) {
        perror("signal error");
        exit(EXIT_FAILURE);
    }
    ret = alarm(3); // 设置定时时间为3s的定时器， 由内核来进行定时
    pause(); // 等待信号
    printf("main process \n");
    return 0;
}
